home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.022.AutoLaunch / start.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  3.1 KB  |  141 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2. *
  3. * autolaunch start.c -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1988-1990
  7. * All Rights Reserved.
  8. *
  9. * Written by Eric Soldan.
  10. *
  11. * Developer Technical Support Apple II Sample Code
  12. *
  13. * This file contains the code needed to start (and quit) autolaunch.
  14. *
  15. **********************************************************************/
  16.  
  17. #include <types.h>
  18. #include <quickdraw.h>
  19. #include <loader.h>
  20. #include <locator.h>
  21. #include <memory.h>
  22. #include <gsos.h>
  23. #include <sane.h>
  24.  
  25. #include "autolaunch.h"
  26.  
  27. void    doFmdStartUp();
  28. void    doFmdShutDown();
  29.  
  30. #ifdef __fmdTool__
  31. static InitialLoadOutputRec        fmdInfo;
  32. #endif
  33.  
  34. /*********************************************************************/
  35.  
  36. main()
  37. {
  38.     Handle            saneHandle;
  39.     Ref                initRef;    /* This holds the reference to the startstop record */
  40.     unsigned int    oldPathLen;
  41.  
  42.     static struct PrefixRecGS quitPrefix0 = {
  43.         2,
  44.         0,
  45.         (GSString255Ptr)launch.targetPath
  46.     };
  47.     static struct PrefixRecGS quitPrefix8 = {
  48.         2,
  49.         8,
  50.         (GSString255Ptr)launch.targetPath
  51.     };
  52.  
  53.     static struct QuitRecGS quit = {
  54.         2,
  55.         NULL,
  56.         onStack+restartable
  57.     };
  58.  
  59.     TLStartUp();
  60.     MMStartUp();
  61.     initPtrCheck(_ownerid);
  62.  
  63.     initRef = StartUpTools(_ownerid, refIsResource, 0x0001L);
  64.         /* Start up the tools using the new toolbox call */
  65.  
  66.     if (!_toolErr) doFmdStartUp();        /* Start up fakeModalDialog.   */
  67.     if (!_toolErr) initGlobals();        /* Initialize our globals.       */
  68.     if (!_toolErr) setupMenus();        /* Set up menus.               */
  69.     if (!_toolErr) InitCursor();        /* Make cursor show ready.       */
  70.     if (!_toolErr) mainEvent();            /* Use application.               */
  71.  
  72.     doFmdShutDown();
  73.     
  74.     ShutDownTools(refIsHandle, initRef);
  75.         /* Let the toolbox shut down the tools. */
  76.  
  77.     closePtrCheck();
  78.     MMShutDown(_ownerid);
  79.     TLShutDown();
  80.  
  81.     if (quitFlag == 2) {
  82.         saneHandle = FindHandle(GetWAP(0,10));
  83.         SANEShutDown();
  84.         DisposeHandle(saneHandle);
  85.  
  86.         oldPathLen = truncFileName(launch.targetPath);
  87.         SetPrefixGS(&quitPrefix0);
  88.         SetPrefixGS(&quitPrefix8);
  89.         *(int *)launch.targetPath = oldPathLen;
  90.  
  91.         quit.pathname = (GSString255Ptr)launch.targetPath;
  92.         PurgeAll(0x1000);    /* So restartable applications can   */
  93.                             /* run a second time after a change. */
  94.         QuitGS(&quit);
  95.     }
  96. }
  97.  
  98. /*********************************************************************/
  99.  
  100. void    doFmdStartUp()
  101. {
  102.     unsigned int    tempID, err;
  103.     static char        fmdName[] = "\p9:FakeModalTool";
  104.  
  105. #ifdef __fmdTool__
  106.  
  107.     fmdInfo.userID = 0;                /* In case we fail.                   */
  108.  
  109.     tempID = GetUserID(fmdName);    /* Get our own ID for the toolset. */
  110.  
  111.     if (!_toolErr) fmdInfo = Restart(tempID);
  112.     if (_toolErr)  fmdInfo = InitialLoad(0x1000, fmdName, 0);
  113.     if (err = _toolErr) {
  114.         InitCursor();
  115.         TLMountVolume(40, 32, "\pYou need fakeModalTool in same",
  116.             "\pfolder as autolaunch.", "\pAgain", "\pCome");
  117.         _toolErr = err;
  118.     }
  119.     else SetTSPtr(userTool, fmdToolNum, fmdInfo.startAddr);
  120.  
  121. #endif
  122.  
  123.     if (!_toolErr) fmdStartUp();
  124. }
  125.  
  126. /*********************************************************************/
  127.  
  128. void    doFmdShutDown()
  129. {
  130.     fmdShutDown();
  131.  
  132. #ifdef __fmdTool__
  133.  
  134.     if (fmdInfo.userID)
  135.         UserShutDown(fmdInfo.userID, 0x4000);    /* restartable from memory */
  136.  
  137. #endif
  138.  
  139. }
  140.  
  141.